home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_200
/
275_02
/
rijn22.c
< prev
next >
Wrap
Text File
|
1980-01-01
|
18KB
|
588 lines
/* rijn22.c */
/* program for lcau22 option 'd' */
/* display de Bruijn diagram - 1st, 2nd, & 3rd gen */
/* Harold V. McIntosh, 20 February 1988 */
/* 21 February 1988 - add j0=i0; to Pass 4's */
/* 3 March 1988 - adapted from lca21.c to lca22.c */
/* Copyright (C) 1987 */
/* Copyright (C) 1988 */
/* Harold V. McIntosh */
/* Gerardo Cisneros S. */
# define JX 0.8 /* x-center, de Bruijn diagram */
# define JY 0.5 /* y-center, de Bruijn diagram */
# define RI 0.455 /* inner radius, de Bruijn diagram */
# define RO 0.475 /* outer radius, de Bruijn diagram */
# define NW 24 /* pause after so many lines */
int dd; /* # points in de Bruijn ring */
int mc, nc, nl; /* column & line control */
/* edit the de Bruijn diagram */
edijn() {char c;
clijn();
dd=KK*KK*KK*KK;
ijn(dd,KK,2);
while (0<1) {
videocursor(0,0,36);
videoputc('?',2);
c=kbdin();
if (c=='\015') break;
videocursor(0,0,38);
videoputc(c,2);
videocursor(0,0,36);
videoputc(' ',2);
videoscroll(1,0,24,14,0,0);
videocursor(0,0,0);
kwait(3);
switch (c) {
case 'A': dd=KK*KK*KK*KK; ijn(dd,KK,2); sijn(dd,0,1); break;
case 'B': dd=KK*KK*KK*KK; ijn(dd,KK,2); sijn(dd,1,1); break;
case 'C': dd=KK*KK*KK*KK; ijn(dd,KK,2); zijn(dd,0,1); break;
case 'D': dd=KK*KK*KK*KK; ijn(dd,KK,2); zijn(dd,1,1); break;
case 'E': dd=KK*KK*KK*KK; ijn(dd,KK,2); zijn(dd,2,1); break;
case 'F': dd=KK*KK*KK*KK; ijn(dd,KK,2); zijn(dd,3,1); break;
case 'G': dd=KK*KK*KK*KK; ijn(dd,KK,2); zijn(dd,4,1); break;
case 'a': kwait(0); printf("Precursors 0*:"); kwait(0); xpass1(0); break;
case 'b': kwait(0); printf("Precursors 1*:"); kwait(0); xpass1(1); break;
case 'c': kwait(0); printf("(1,-2) gliders:"); kwait(0); apass1(0); break;
case 'd': kwait(0); printf("(1,-1) gliders:"); kwait(0); apass1(1); break;
case 'e': kwait(0); printf("(1,0) static:"); kwait(0); apass1(2); break;
case 'f': kwait(0); printf("(1,1) gliders:"); kwait(0); apass1(3); break;
case 'g': kwait(0); printf("(1,2) gliders:"); kwait(0); apass1(4); break;
case 'h': kwait(0); printf("(2,-4) gliders:"); kwait(0); bpass1(0); break;
case 'i': kwait(0); printf("(2,-3) gliders:"); kwait(0); bpass1(1); break;
case 'j': kwait(0); printf("(2,-2) gliders:"); kwait(0); bpass1(2); break;
case 'k': kwait(0); printf("(2,-1) gliders:"); kwait(0); bpass1(3); break;
case 'l': kwait(0); printf("(2,0) cycles:"); kwait(0); bpass1(4); break;
case 'm': kwait(0); printf("(2,1) gliders:"); kwait(0); bpass1(5); break;
case 'n': kwait(0); printf("(2,2) gliders:"); kwait(0); bpass1(6); break;
case 'o': kwait(0); printf("(2,3) gliders:"); kwait(0); bpass1(7); break;
case 'p': kwait(0); printf("(2,4) gliders:"); kwait(0); bpass1(8); break;
case '1': dd=KK*KK*KK*KK; clijn(); ijn(dd,KK,2); break;
case '2': dd=KK*KK*KK*KK*KK*KK*KK*KK; clijn(); ijn(dd,KK,2); break;
case '3': dd=KK*KK*KK*KK*KK; clijn(); ijn(dd,KK,2); break;
case '4': dd=KK*KK*KK*KK*KK*KK; clijn(); ijn(dd,KK,2); break;
case '5': dd=KK*KK*KK*KK*KK*KK*KK; clijn(); ijn(dd,KK,2); break;
case '+': videopalette(WHCYMAG); break;
case '-': videopalette(YELREGR); break;
case '?': case '/': clijn(); break;
default: break;
}; /* end switch */
}; /* end while */
videopalette(WHCYMAG);
videomode(T80X25);
}
/* clear edijn screen and set up menu */
clijn() {
videomode(COLGRAF);
videopalette(YELREGR);
videocursor(0,0,0);
scrrul();
videocursor(0,3,0);
printf("de Bruijn ring\n\n");
printf("ab - 0*,1*\n");
printf("AB - full n*\n");
printf("cdefg - (1,x)\n");
printf("CDEFG - (all)\n");
printf("h.l.p - (2,x)\n");
printf("12345 - diagram\n");
printf("+- - pallette\n");
printf("?/ - clr scrn\n");
printf("<cr> - exit\n\n");
}
/* generate a de Bruijn diagram with m nodes, n links per node, color l */
ijn(m,n,l) int m, n, l; {
int i, j;
double ii, jj, nn, x, y, t, h;
double sin(), cos();
nn=(double)(n);
t=6.28318/((double)(m));
h=0.5*t;
for (i=0; i<m; i++) {
ii=(double)(i);
for (j=0; j<n; j++) {
jj=(double)(j);
x=JX-RI*sin(ii*t+h);
y=JY-RI*cos(ii*t+h);
videoline(x,y,0);
x=JX-RO*sin((nn*ii+jj)*t+h);
y=JY-RO*cos((nn*ii+jj)*t+h);
videoline(x,y,l);
};
};
}
/* insert a link into a de Bruijn diagram */
/* m - number of vertices */
/* u - initial vertex */
/* v - terminal vertex */
/* l - color of link */
lijnk(m,u,v,l) int m, u, v, l; {
double uu, vv, x, y, t, h;
double sin(), cos();
t=6.28318/((double)(m));
uu=t*((double)(u));
vv=t*((double)(v));
h=0.5*t;
x=JX-RI*sin(uu+h);
y=JY-RI*cos(uu+h);
videoline(x,y,0);
x=JX-RO*sin(vv+h);
y=JY-RO*cos(vv+h);
videoline(x,y,l);
}
/* generate a de Bruijn diagram showing antecedents of state k in color l */
sijn(m,k,l) int m, k, l; {
int i0, i1, i2, i3, i4;
double th, x, y, t, h;
double sin(), cos();
t=6.28318/((double)(m));
h=0.5*t;
for (i0=0; i0<KK; i0++) {
for (i1=0; i1<KK; i1++) {
for (i2=0; i2<KK; i2++) {
for (i3=0; i3<KK; i3++) {
for (i4=0; i4<KK; i4++) {
if (k==ascrule[i0][i1][i2][i3][i4]-'0') {
th=((double)(((i0*KK+i1)*KK+i2)*KK+i3)*t+h);
x=JX-RI*sin(th);
y=JY-RI*cos(th);
videoline(x,y,0);
th=((double)(((i1*KK+i2)*KK+i3)*KK+i4)*t+h);
x=JX-RO*sin(th);
y=JY-RO*cos(th);
videoline(x,y,l);
}; /* end if */
};};};};}; /* end for's */
} /* end sijn */
/* generate a de Bruijn diagram showing the (1,k) links in color l */
zijn(m,k,l) int m, k, l; {
int i, i0, i1, i2, i3, i4;
double th, x, y, t, h;
double sin(), cos();
t=6.28318/((double)(m));
h=0.5*t;
for (i0=0; i0<KK; i0++) {
for (i1=0; i1<KK; i1++) {
for (i2=0; i2<KK; i2++) {
for (i3=0; i3<KK; i3++) {
for (i4=0; i4<KK; i4++) {
i=ascrule[i0][i1][i2][i3][i4]-'0';
if ((k==0&&i==i0)||(k==1&&i==i1)||(k==2&&i==i2)||(k==3&&i==i3)||(k==4&&i==i4)) {
th=((double)(((i0*KK+i1)*KK+i2)*KK+i3)*t+h);
x=JX-RI*sin(th);
y=JY-RI*cos(th);
videoline(x,y,0);
th=((double)(((i1*KK+i2)*KK+i3)*KK+i4)*t+h);
x=JX-RO*sin(th);
y=JY-RO*cos(th);
videoline(x,y,l);
}; /* end if */
};};};};}; /* end for's */
} /* end zijn */
/* plot graph on video screen */
/* move pen from present position to (x,y) */
/* raised if l=0; color l if l>0 */
videoline(x,y,l) double x, y; int l; {
int k, ax, ay, dx, dy, di, dj, x1, y1;
/* if (x<0.0) return; if (x>1.0) return */
/* if (y<0.0) return; if (y>1.0) return */
x1=(int)(199.0*(1.0-y));y1=(int)(199.0*x);
dx=x1-ix0;
dy=y1-iy0;
ax=dx>=0?dx:-dx;
ay=dy>=0?dy:-dy;
di=dx>=0?1:-1; if (dx==0) di=0;
dj=dy>=0?1:-1; if (dy==0) dj=0;
if (l>0) {if (ax!=0 || ay!=0) {
if (ax>=ay) {for (k=0; k<=ax; k++) videodot(ix0+di*k,60+iy0+(k*dy)/ax,l);}
else {for (k=0; k<=ay; k++) videodot(ix0+(k*dx)/ay,60+iy0+dj*k,l);};
}; };
ix0=x1;
iy0=y1;
}
/* approximation to sine */
double sin(x) double x; {
if (x<0.0) return(-sin(-x));
while (x>=6.28318) x-=6.28318;
if (x>=3.142) return(-sin(x-3.14159));
if (x>=1.571) return(sin(3.14159-x));
return(x*(1.0-0.166*(x*x-0.05*x*x)));
}
/* approximation to cosine */
double cos(x) double x; {double sin(); return(sin(x+1.57079));}
/* ONE22.C */
/* Pass 1a analyzes all the configurations which fulfil (1,-1+l) */
apass1(l) int l; {
char arry[KK][KK][KK][KK][KK];
int i0, i1, i2, i3, i4, m;
mc=1;
asctobin();
printf(" Pass1a\015");
for (i0=0; i0<KK; i0++) {
for (i1=0; i1<KK; i1++) {
for (i2=0; i2<KK; i2++) {
for (i3=0; i3<KK; i3++) {
for (i4=0; i4<KK; i4++) {
switch (l) {
case 0: m=i0; break;
case 1: m=i1; break;
case 2: m=i2; break;
case 3: m=i3; break;
case 4: m=i4; break;
default: break;};
arry[i0][i1][i2][i3][i4]=binrule[i0][i1][i2][i3][i4]==m?'Y':'N';
};};};};};
apass2i(arry);
apass2o(arry);
apass4(arry);
}
/* Pass 1x analyzes all the configurations mapping into a constant */
xpass1(c) int c; {
char arry[KK][KK][KK][KK][KK];
int i0, i1, i2, i